package com.ant.storage.service.impl;


import com.ant.storage.common.ResultCode;
import com.ant.storage.dto.DepreciationDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.Commodity;
import com.ant.storage.pojo.DepreciationDetails;
import com.ant.storage.mapper.DepreciationDetailsMapper;
import com.ant.storage.service.IDepreciationDetailsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author melon
 * @since 2023-12-23
 */
@Service
public class DepreciationDetailsServiceImpl extends ServiceImpl<DepreciationDetailsMapper, DepreciationDetails> implements IDepreciationDetailsService {

    @Override
    public DepreciationDetails last(Integer id,Integer tid) {
        return this.baseMapper.last(id,tid);
    }

    @Override
    public PageInfo<DepreciationDetails> getPageList(DepreciationDto dto) {
        try {
            PageHelper.startPage(dto.getPageIndex(), dto.getPageSize());
            QueryWrapper<DepreciationDetails> wrapper = new QueryWrapper<>();
            if (StringUtils.isNotEmpty(dto.getDepreciationName())) {
                wrapper.lambda().like(DepreciationDetails::getDepreciationName, dto.getDepreciationName());
            }
            if (dto.getCityId()!=null) {
                wrapper.lambda().like(DepreciationDetails::getCityId, dto.getCityId());
            }
            if (StringUtils.isNotEmpty(dto.getPeriodsCode())) {
                wrapper.lambda().like(DepreciationDetails::getPeriodsCode, dto.getPeriodsCode());
            }
            wrapper.orderByDesc("id");
            PageInfo<DepreciationDetails> info = new PageInfo<>(this.baseMapper.selectList(wrapper));
            return info;
        } catch (Exception e) {
            throw new AntException(ResultCode.BODY_NOT_MATCH);
        }
    }
}
